package LinkedListPackage2;

import LinkedListPackage.ListNode;

/**
 * @author Lzm
 * @version 1.0
 */
public class removeNthFromEnd_ {

  public ListNode removeNthFromEnd(ListNode head, int n) {
    if (head == null){
      return head;
    }
    ListNode dummyHead = new ListNode();
    dummyHead.next = head;
    ListNode slow = dummyHead;
    ListNode fast = dummyHead;
    for (int i = 0 ; i < n ; i++){
      fast = fast.next;
    }
    while(fast.next != null){
      slow = slow.next;
      fast = fast.next;
    }
    slow.next = slow.next.next;
    return dummyHead.next;
  }
}
